<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('签收单据')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-logistics-sign" th:object="${logistics}" enctype="multipart/form-data">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">签收时间：</label>
            <div class="col-sm-8">
                <input type="text" class="time-input" placeholder="签收时间" name="signTime"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">附件：</label>
            <div class="col-sm-8">
                <input type="file" class="file-input" placeholder="签收时间" name="files" multiple/>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>确 认
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/logistics";
    $("#form-logistics-sign").validate({
        focusCleanup: true
    });

    function submitHandler() {
        var signTime = document.querySelector('input[name="signTime"]').value;
        var remark = document.querySelector('textarea[name="remark"]').value;
        var files = document.querySelector('input[name="files"]').files;
        if (signTime === null || signTime === '') {
            $.modal.alertError('请填写签收时间');
            return;
        }
        if (remark === null || remark === '') {
            $.modal.alertError('请填写备注信息');
            return;
        }
        if (files === null || files.length === 0) {
            $.modal.alertError('请上传附件信息');
            return;
        }
        var formData = new FormData();
        formData.append('id', document.querySelector('input[name="id"]').value);
        formData.append('signTime', signTime);
        formData.append('remark', remark);
        for (var i = 0; i < files.length; i++) {
            formData.append('files', files[i]);
        }
        $.ajax({
            url: prefix + "/sign",
            type: "post",
            data: formData,
            processData: false,
            contentType: false,
            beforeSend: function () {
                $.modal.loading("正在处理中，请稍候...");
            },
            success: function (result) {
                if (typeof callback == "function") {
                    callback(result);
                }
                $.operate.successTabCallback(result);
            }
        });
    }
</script>
</body>
</html>